package site.jlopen.components.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import site.jlopen.components.entity.GrapGroup;
import site.jlopen.components.entity.GraphNode;

public class GrapDataUtil {
	
	/*public static void main(String[] args) {
		List<GrapGroup> gs = getGrapGroup();
		List<GraphNode> nds = new ArrayList<GraphNode>();
		for (GrapGroup grapGroup : gs) {
			List<GraphNode> nd = grapGroup.getNodes();
			if(null != nd && nd.size() > 0) {
				nds.addAll(nd);
			}
		}
		 Path sourcePath = Paths.get("E:\\all-code-workspace\\eclipse\\work\\secretpad-sdk-master\\secretpad-ui\\src\\main\\resources\\config\\flow.json");
		for (GraphNode graphNode : nds) {
			Path destinationPath = Paths.get("E:\\all-code-workspace\\eclipse\\work\\secretpad-sdk-master\\secretpad-ui\\src\\main\\resources\\config\\"+graphNode.getId()+".json");
			 
	        try {
	            Files.copy(sourcePath, destinationPath, StandardCopyOption.REPLACE_EXISTING);
	            System.out.println("文件复制成功！");
	        } catch (IOException e) {
	            System.out.println("文件复制失败: " + e.getMessage());
	        }
		}
	}*/
	static Map<String, String> grapGroupNameMap = new HashMap<String, String>();
	static {
		grapGroupNameMap.put("", null);
	}
	
	public static String getGrapGroupName(String domainName) {
		return grapGroupNameMap.get(domainName);
	}
	public static List<GrapGroup> getGrapGroup() {
		List<GrapGroup> list = new ArrayList<GrapGroup>();
		
		/*GraphNode html = new GraphNode("测试HTML", "html")             .CUSTOMFLOW().addPort("top").addPort("top").addPort("bottom");
		list.add(new GrapGroup("html节点", "html")
				.addNode(html));*/
		
		/*list.add(new GrapGroup("已激活组件", "active_com")
				.addNode(new GraphNode("读取数据", "read_data")          .SECRETFLOW().addPort("bottom"))
				.addNode(new GraphNode("隐私求交", "psi")                .SECRETFLOW().addPort("top").addPort("top").addPort("bottom"))
				.addNode(new GraphNode("全表统计", "table_statistics")   .SECRETFLOW().addPort("top"))
				);*/
		
		list.add(new GrapGroup("数据准备", "data_prep")
				.addNode(new GraphNode("表union", "union")              .SECRETFLOW().addPort("top").addPort("top").addPort("bottom"))
				//.addNode(new GraphNode("样本表", "datatable")           .CUSTOMFLOW().addPort("bottom"))
				.addNode(new GraphNode("隐私求交", "psi")                 .SECRETFLOW().addPort("top").addPort("top").addPort("bottom"))
				.addNode(new GraphNode("表随机分割", "train_test_split")   .SECRETFLOW().addPort("top").addPort("bottom").addPort("bottom"))
				);

		list.add(new GrapGroup("数据过滤", "data_filter")
				.addNode(new GraphNode("条件过滤", "condition_filter")     .SECRETFLOW().addPort("top").addPort("top").addPort("bottom"))
				.addNode(new GraphNode("行级过滤", "expr_condition_filter").SECRETFLOW().addPort("top").addPort("top").addPort("bottom"))
				.addNode(new GraphNode("列级过滤", "feature_filter")       .SECRETFLOW().addPort("top").addPort("bottom"))
				.addNode(new GraphNode("采样", "sample")                  .SECRETFLOW().addPort("top").addPort("bottom"))
				);
		
		//list.add(new GrapGroup("后处理", "postprocessing")
				//.addNode(new GraphNode("评分卡转换", "score_card_transformer")       .SECRETFLOW().addPort("top").addPort("bottom"))
				//);
		
		list.add(new GrapGroup("预处理", "preprocessing")
				.addNode(new GraphNode("二元操作", "binary_op")                      .SECRETFLOW().addPort("top").addPort("bottom").addPort("bottom"))
				.addNode(new GraphNode("交叉决策", "case_when")                      .SECRETFLOW().addPort("top").addPort("bottom").addPort("bottom"))
				.addNode(new GraphNode("类型转换", "cast")                           .SECRETFLOW().addPort("top").addPort("bottom").addPort("bottom"))
				.addNode(new GraphNode("特征计算", "feature_calculate")              .SECRETFLOW().addPort("top").addPort("bottom").addPort("bottom"))
				.addNode(new GraphNode("异常值填充", "fillna")                        .SECRETFLOW().addPort("top").addPort("bottom").addPort("bottom"))
				.addNode(new GraphNode("onehot_encode", "onehot_encode")           .SECRETFLOW().addPort("top").addPort("bottom"))
				.addNode(new GraphNode("特征工程应用", "substitution")                .SECRETFLOW().addPort("top").addPort("top").addPort("bottom"))
				.addNode(new GraphNode("分箱转换", "vert_bin_substitution")          .SECRETFLOW().addPort("top").addPort("top").addPort("bottom"))
				

				//.addNode(new GraphNode("隐私求交", "psi")               .TRUSTEDFLOW().addPort("top").addPort("top").addPort("bottom"))
				//.addNode(new GraphNode("特征过滤", "feature_filter").TRUSTEDFLOW().addPort("top").addPort("top").addPort("bottom"))
				//.addNode(new GraphNode("随机分割", "train_test_split").TRUSTEDFLOW().addPort("top").addPort("bottom"))
				
				//.addNode(new GraphNode("评分卡转换", "score_card_transformer")       .addPort("top").addPort("bottom"))
				//.addNode(new GraphNode("线性模型参数修改", "model_param_modifications").addPort("top").addPort("bottom")).addPort("bottom"))
				//.addNode(new GraphNode("常规分箱", "vert_binning")         .addPort("top").addPort("bottom"))
				//.addNode(new GraphNode("WOE分箱", "vert_woe_binning")     .addPort("top").addPort("bottom"))
				//.addNode(new GraphNode("分箱修改", "binning_modifications").addPort("top").addPort("bottom"))
				);

		list.add(new GrapGroup("特征工程", "feature")
				.addNode(new GraphNode("常规分箱", "vert_binning")         .SECRETFLOW().addPort("top").addPort("bottom"))
				.addNode(new GraphNode("WOE分箱", "vert_woe_binning")     .SECRETFLOW().addPort("top").addPort("bottom"))
				);

		list.add(new GrapGroup("统计", "stats")
				.addNode(new GraphNode("分组统计", "groupby_statistics").SECRETFLOW().addPort("top"))
				.addNode(new GraphNode("相关系数矩阵", "ss_pearsonr")    .SECRETFLOW().addPort("top"))
				.addNode(new GraphNode("VIF指标计算", "ss_vif")          .SECRETFLOW().addPort("top"))
				.addNode(new GraphNode("群体稳定性", "stats_psi")        .SECRETFLOW().addPort("top").addPort("top").addPort("top"))
				.addNode(new GraphNode("全表统计", "table_statistics")   .SECRETFLOW().addPort("top"))
				

				//.addNode(new GraphNode("相关系数矩阵", "pearsonr")    .TRUSTEDFLOW().addPort("top"))
				//.addNode(new GraphNode("VIF指标计算", "vif")    .TRUSTEDFLOW().addPort("top"))
				//.addNode(new GraphNode("全表统计", "table_statistics")    .TRUSTEDFLOW().addPort("top"))
				);

		list.add(new GrapGroup("模型训练", "ml.train")
				//.addNode(new GraphNode("LR训练", "lr_train")              .TRUSTEDFLOW().addPort("top"))
				//.addNode(new GraphNode("XGB训练", "xgb_train")  .TRUSTEDFLOW().addPort("top").addPort("bottom"))
				.addNode(new GraphNode("SecureBoost训练", "sgb_train").SECRETFLOW().addPort("top").addPort("bottom"))
				.addNode(new GraphNode("拆分学习NN训练", "slnn_train")   .SECRETFLOW().addPort("top").addPort("top").addPort("bottom"))
				.addNode(new GraphNode("SSGLM训练", "ss_glm_train")   .SECRETFLOW().addPort("top").addPort("bottom"))
				.addNode(new GraphNode("逻辑回归训练", "ss_sgd_train")  .SECRETFLOW().addPort("top").addPort("bottom"))
				.addNode(new GraphNode("SS-XGB训练", "ss_xgb_train")  .SECRETFLOW().addPort("top").addPort("bottom"))
				);

		list.add(new GrapGroup("模型预测", "ml.predict")
				//.addNode(new GraphNode("LR预测", "lr_predict")              .TRUSTEDFLOW().addPort("top"))
				//.addNode(new GraphNode("XGB预测", "xgb_predict")  .TRUSTEDFLOW().addPort("top").addPort("top").addPort("bottom"))
				.addNode(new GraphNode("SecureBoost预测", "sgb_predict").SECRETFLOW().addPort("top").addPort("top").addPort("bottom"))
				.addNode(new GraphNode("拆分学习NN预测", "slnn_predict")   .SECRETFLOW().addPort("top").addPort("top").addPort("bottom"))
				.addNode(new GraphNode("SSGLM预测", "ss_glm_predict")   .SECRETFLOW().addPort("top").addPort("top").addPort("bottom"))
				.addNode(new GraphNode("逻辑回归预测", "ss_sgd_predict")  .SECRETFLOW().addPort("top").addPort("top").addPort("bottom"))
				.addNode(new GraphNode("SS-XGB预测", "ss_xgb_predict")  .SECRETFLOW().addPort("top").addPort("top").addPort("bottom"))
				);

		list.add(
				new GrapGroup("模型评估", "ml.eval")
				.addNode(new GraphNode("二分类评估", "biclassification_eval") .SECRETFLOW().addPort("top"))
				.addNode(new GraphNode("预测偏差评估", "prediction_bias_eval").SECRETFLOW().addPort("top"))
				.addNode(new GraphNode("回归模型评估", "regression_eval")     .SECRETFLOW().addPort("top"))
				.addNode(new GraphNode("P-VALUE评估", "ss_pvalue")          .SECRETFLOW().addPort("top").addPort("top"))
						);
		list.add(
				new GrapGroup("IO系列", "io")
				.addNode(new GraphNode("恒等", "identity")    .SECRETFLOW().addPort("top").addPort("bottom"))
				.addNode(new GraphNode("读取数据", "read_data").SECRETFLOW().addPort("bottom"))
				.addNode(new GraphNode("写入数据", "write_data").SECRETFLOW().addPort("top").addPort("bottom"))
				);
		
		list.add(
				new GrapGroup("模型", "model")
				.addNode(new GraphNode("模型导出", "model_export")    .SECRETFLOW().addPort("top").addPort("bottom"))
				//.addNode(new GraphNode("读取数据", "read_data").SECRETFLOW().addPort("top").addPort("bottom"))
				//.addNode(new GraphNode("写入数据", "write_data").SECRETFLOW().addPort("top").addPort("bottom"))
				);
		return list;
	}
	
	/*public static Map<String, GraphNodeParam> getGrapNodeParam() {
		Map<String, GraphNodeParam> map = new HashMap<String, GraphNodeParam>();
		GraphNodeParam psi = new GraphNodeParam();
		psi.addAttr(new GraphNodeAttr().setName("协议").setCode("protocol").setType("string").setDesc("PSI 协议")
				.setDefVal("PROTOCOL_RR22")
				.addPossible("PROTOCOL_RR22").addPossible("PROTOCOL_ECDH").addPossible("PROTOCOL_KKRT").setRequired(true));
		psi.addAttr(new GraphNodeAttr().setName("排序结果").setCode("sort_result").setType("boolean").setDesc("It false, output is not promised to be aligned. Warning: disable this option may lead to errors in the following components. DO NOT TURN OFF if you want to append other components.")
				.setDefVal("True")
				.addPossible("False").addPossible("True"));
		psi.addAttr(new GraphNodeAttr().setName("ECDH 曲线类型").setCode("ecdh_curve").setType("string").setDesc("ECDH PSI的曲线类型")
				.setDefVal("CURVE_FOURQ")
				.addPossible("CURVE_25519").addPossible("CURVE_FOURQ").addPossible("CURVE_SM2").addPossible("CURVE_SECP256K1"));
		psi.addAttr(new GraphNodeAttr().setName("允许双主键").setCode("allow_duplicate_keys").setType("string").setDesc("Some join types allow duplicate keys. If you specify a party to receive, this should be no")
				.addPossible("no").addPossible("yes").setRequired(true));
		psi.addIn("input_table_1", "sf.table.individual", "Individual table for party 1");
		psi.addIn("input_table_2", "sf.table.individual", "Individual table for party 2");
		psi.addOut("psi_output", "sf.table.vertical_table or sf.table.individual", "输出联合表");
		map.put("psi", psi);
		return map;
	}*/
	
}
